﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AppConfigSection.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the AppConfigSection class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine
{
    using System;
    using System.Configuration;
    using System.Globalization;
    
    /// <summary>
    /// Defines the AppConfigSection class.
    /// </summary>
    public class AppConfigSection : ConfigurationSection
    {
        /// <summary>
        /// Gets or sets the application's title.
        /// </summary>
        [ConfigurationProperty("title", IsRequired = false)]
        public string Title
        {
            get
            {
                return (string)this["title"];
            }

            set
            {
                this["title"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's domain.
        /// </summary>
        [ConfigurationProperty("domain", IsRequired = true)]
        [StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\")]
        public string Domain
        {
            get
            {
                return (string)this["domain"];
            }

            set
            {
                this["domain"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's logon page.
        /// </summary>
        [ConfigurationProperty("logonUrl", DefaultValue = "/logon.aspx", IsRequired = true)]
        public Uri LogOnUrl
        {
            get
            {
                return new Uri(this["logonUrl"].ToString(), UriKind.Relative);
            }

            set
            {
                this["logonUrl"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's error page.
        /// </summary>
        [ConfigurationProperty("errorUrl", DefaultValue = "/error.aspx", IsRequired = true)]
        public Uri ErrorUrl
        {
            get
            {
                return new Uri(this["errorUrl"].ToString(), UriKind.Relative);
            }

            set
            {
                this["errorUrl"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's database connection string name.
        /// </summary>
        [ConfigurationProperty("connectionStringName", IsRequired = true)]
        public string ConnectionStringName
        {
            get
            {
                return (string)this["connectionStringName"];
            }

            set
            {
                this["connectionStringName"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's active directory connection username.
        /// </summary>
        [ConfigurationProperty("adUsername", IsRequired = false)]
        public string ADUserName
        {
            get
            {
                return (string)this["adUsername"];
            }

            set
            {
                this["adUsername"] = value;
            }
        }

        /// <summary>
        /// Gets or sets the application's active directory connection password.
        /// </summary>
        [ConfigurationProperty("adPassword", IsRequired = false)]
        public string ADPassword
        {
            get
            {
                return (string)this["adPassword"];
            }

            set
            {
                this["adPassword"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether or not to require SSL.
        /// </summary>
        [ConfigurationProperty("useSsl", DefaultValue = false, IsRequired = false)]
        public bool UseSsl
        {
            get
            {
                return Convert.ToBoolean(this["useSsl"], CultureInfo.InvariantCulture);
            }

            set
            {
                this["useSsl"] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether or not to allow setup.
        /// </summary>
        [ConfigurationProperty("allowSetup", DefaultValue = false, IsRequired = false)]
        public bool AllowSetup
        {
            get
            {
                return Convert.ToBoolean(this["allowSetup"], CultureInfo.InvariantCulture);
            }

            set
            {
                this["allowSetup"] = value;
            }
        }
    }
}